/**
 * Created by wangshuyi on 2016/12/27.
 */

'use strict';

/**
 * 公众号
 */

const uuid = require('uuid');
const mongoose = require('../util/mongoDB'),
    Schema = mongoose.Schema;
const config = require('../../config/config');

const schema = new Schema({
    _id : {type : String, default: uuid.v4},
    code : { type: String, default: uuid.v4},       //编码

    rule : { type: String },                        //奖品名称
    remainCount:{ type: Number},                    //剩余数量
    totalCount:{ type: Number},                     //全部数量
    eventId : { type: String, ref: "PrizeEvent" },  //活动id
    prizeType: { type: String },                    //奖品类型
    chance:{type:String},                           //中奖概率

    priceName:{type:String},                        //实物名称
    point:{type:Number},                            //积分数量
    giftCode:{type:String},                         //礼券code
    giftName:{type:String},                         //礼券名称
    giftPrice:{type:String},                        //礼券金额
    giftRemark:{type:String},                       //礼券说明
    prizeNumber:{type:Number},                      //中奖次数

    expireTime : { type: Date },                   //过期时间
    awardFlag : { type: Number },                  //是否已发奖

    officialAccount : { type: String,ref:"OfficialAccount"},                            //所属公众号
    state : { type: Number, default : 1},           //是否有效
    createTime: {type: Date, default: Date.now},    //创建时间
    creater: {type: String, ref : "User", default: config.dbUser.robot._id},          //创建者
    updateTime : { type: Date, default: Date.now},  //最后更新时间
    updater : { type: String, ref : "User", default: config.dbUser.robot._id}         //最后更新者
});

const model = mongoose.model('PrizeRule',schema);


module.exports = model;
